/**
 * Copyright (C) 2021-2022 maminjie <canpool@163.com>
 * SPDX-License-Identifier: LGPL-2.1
 * Powered by Qt-Advanced-Docking-System
**/

#pragma once

#include "qads_global.h"
#include <QWidget>

#include <QIcon>

QADS_BEGIN_NAMESPACE

class DockFloatingWidget;
class DockFloatingWidgetTitleBarPrivate;

/**
 * Titlebar for floating widgets to capture non client are mouse events.
 * Linux does not support NonClientArea mouse events like
 * QEvent::NonClientAreaMouseButtonPress. Because these events are required
 * for the docking system to work properly, we use our own titlebar here to
 * capture the required mouse events.
 */
class DockFloatingWidgetTitleBar : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(QIcon maximizeIcon READ maximizeIcon WRITE setMaximizeIcon)
    Q_PROPERTY(QIcon normalIcon READ normalIcon WRITE setNormalIcon)
public:
    explicit DockFloatingWidgetTitleBar(DockFloatingWidget *parent = nullptr);
    ~DockFloatingWidgetTitleBar() override;

    void setTitle(const QString &text);
    void setClosable(bool enable);
    void updateStyle();

    void setMaximizedIcon(bool maximized);
    void enableCloseButton(bool enable);

signals:
    void closeRequested();
    void maximizeRequested();

protected:
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent *event) override;
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;

    QIcon maximizeIcon() const;
    void setMaximizeIcon(const QIcon &icon);
    QIcon normalIcon() const;
    void setNormalIcon(const QIcon &icon);

private:
    DockFloatingWidgetTitleBarPrivate *d;
};

QADS_END_NAMESPACE
